package de.saarland.uni.lego3d.server;

/**
 * This class describes the datatstructure of a virtual lego brick.
 * It holds information about color and layout (width, depth)
 * Every legobrick has the same height in our application.
 */
public class Legobrick {

	/** 
	 * array containing information about the habit of the brick 
	 * example: a lego brick that has a L-Form is represented by 2-1-1
	 * 
	 * TODO: We use this structure to be able to even create strange bricks like L- or U-forms.
	 * 		 Nevertheless, we take out such bricks from the selection in the android app, since we still have
	 * 		 some issues with the collision model of Java3D
	 */
	private int[] brickLayout;
	
	/**
	 * The height of this brick.
	 * The default value is 1 and we do not use other heights right now
	 */
	private int height = 1;
	
	/**
	 * color of the brick
	 */
	public int color;
	
	/**
	 * Creates a Lego brick with the given parameters.
	 * @param layout - the layout of the brick
	 * @param c - color of the brick
	 */
	public Legobrick(int [] layout, int c) {
		brickLayout = layout;
		color = c;
	}
	
	public Legobrick() {
		//We need the default constructur for Java3D internals
	}

	/**
	 * Sets the layout to the given one.
	 * @param layout to set
	 */
	public void setLayout(int ... layout) {
		this.brickLayout = layout;
	}
	
	/**
	 * Returns the layout of the brick as array.
	 */
	public int[] getLayout() {
		return this.brickLayout;
	}

	/**
	 * Sets the color to the given one.
	 * @param color to set
	 */
	public void setColor(int color) {
		this.color = color;
	}
	
	public void setHeight (int height) {
		if (height > 0) {
			this.height = height;
		}
	}
	
	public int getHeight () {
		return height;
	}
	
	/**
	 * Returns a representation of the layout array as string.
	 * Used for debugging
	 */
	public String layoutToString() {
		String res = "";
		for (int i : brickLayout) {
			res += i + ", ";
		}
		return res;
	}
	
	/**
	 * Returns the highest depth value of this brick.
	 * Used for border collistion
	 */
	public int getHeighestDepth() {
		int result = 0;
		
		for (int i : brickLayout) {
			if (i > result)
				result = i;
		}
			
		return result;
	}
}
